﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Wozuji.Logic;
using Wozuji.Logic.Users;

/// <summary>
///login 的摘要说明
/// </summary>
[WebService(Namespace = "http://wozuji.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。 
 [System.Web.Script.Services.ScriptService]
public class login : System.Web.Services.WebService
{

    public login()
    {

        //如果使用设计的组件，请取消注释以下行 
        //InitializeComponent(); 
    }
    Wozuji.Logic.Users.Users u = new Wozuji.Logic.Users.Users();

    [WebMethod(Description = "User login", EnableSession = true)]

    public string userlogin(String name,String pass,String issave)
    {
        
        bool flag=false;
        flag=(issave=="0")?false:true;
      
        if (u.userLogin(name, pass, flag))
        {
            return "1";
        }
        else
        {
            return "0";   
        }
    }
    [WebMethod(Description = "check email valid")]
    public string hadreg(String email)
    {
        
        if (u.mailExist(email))
        {
            return "1";
        }
        else
        {
            return "0";
        }
    }
    [WebMethod(Description = "check valid code", EnableSession = true)]
    public string checkvalidcode(String code)
    {
        if (Session["CheckCode"].ToString().ToUpper().Equals(code.ToUpper()))
        {
            return "1";

        }
        else
        {
            return "0";
        }
    }

    [WebMethod(Description = "add user", EnableSession = true)]
    public string register(String email,String pass,String friendname,String validcode)
    {
        if (!(Session["CheckCode"].ToString().ToUpper().Equals(validcode.ToUpper())))
        {
            //验证码错误
            return "-1";

        }
        else
        {
            if (u.adusers(email, friendname, pass, friendname) != 0)
            {
                return "1";
            }
            else
            {
                return "0";
            }
        }
    }
    [WebMethod(Description = "resetpass", EnableSession = true)]
    public String getbackpass(String email)
    {
        if (u.mailExist(email))
        {
            if (u.getBackPassword(email))
            {
                return "1";
            }
            else
            {
                return "0";
            }
        }
        else
        {
            return "-1";
        }
    
    }


}

